from PyQt5.Qt import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('demo_346_qssfile')
        self.resize(500, 500)
        self.setup_ui()
        QMetaObject.connectSlotsByName(self)

    def setup_ui(self):
        self.qss_test()

    def qss_test(self):
        widget1 = QWidget()
        widget1.setObjectName('widget1')

        widget2 = QWidget()
        widget2.setObjectName('widget2')

        v_layout = QVBoxLayout(self)
        v_layout.addWidget(widget1)
        v_layout.addWidget(widget2)
        self.setLayout(v_layout)

        btn1 = QPushButton('btn1', widget1)
        btn1.setObjectName('btn1')
        btn1.move(50, 100)

        btn2 = QPushButton('btn2', widget2)
        btn2.setObjectName('btn2')
        btn2.move(50, 100)

        lbl1 = QLabel('lbl1', widget1)
        lbl1.resize(100, 50)
        lbl1.setObjectName('lbl1')
        lbl1.setProperty('notice_level', 'warning')
        lbl1.move(150, 100)
        lbl2 = QLabel('lbl2', widget2)
        lbl2.resize(100, 50)
        lbl2.setObjectName('lbl2')
        lbl2.setProperty('notice_level', 'error')

        lbl2.move(150, 100)
        # # wiget 级别
        # with open('demo_346_qss_test.qss', 'r') as qss_read:
        #     qss_content = qss_read.read()
        #     self.setStyleSheet(qss_content)


if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)

    win = Window()
    win.show()
    # app 级别
    with open('demo_346_qss_test.qss', 'r',encoding='utf8') as qss_read:
        qss_content = qss_read.read()
        app.setStyleSheet(qss_content)

    sys.exit(app.exec_())
